﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using System.Collections;

public class MsgTipsLogic
{
    private static MsgTipsLogic self;
    private int totalNum = 0;
    private float baseTime = 2.0f;
    private float eachTime = 0.5f;

    private GameObjectPool objPool;

    public MsgTipsLogic()
    {
        GameObject obj = GameObject.Find("Cube");
        objPool = new GameObjectPool();
        objPool.InitGameObjectPool(obj, 10, null, false);
    }

    public int TotalTipsNums
    {
        set { totalNum = value; }
        get { return totalNum; }
    }

    public GameObjectPool MsgTipsPool
    {
        get { return objPool; }
    }

    public static MsgTipsLogic getInstance()
    {
        if(self == null)
        {
            self = new MsgTipsLogic();
        }
        return self;
    }

    /// <summary>
    /// 任意位置,显示弹出Tips
    /// </summary>
    /// <param name="mesInfo">弹出内容</param>
    /// <param name="postion">弹出位置</param>
    /// <param name="offset">弹出y轴偏移</param>
    public void ShowInfo(string mesInfo, Vector3 postion, float offset)
    {
        try
        {

            float time = baseTime + totalNum * eachTime;

            GameObject showTipsObj = objPool.Spawn(postion);

            Hashtable args = new Hashtable();

            args.Add("easeType", iTween.EaseType.linear);

            args.Add("time", time);

            args.Add("loopType", "none");

            args.Add("onstart", "AnimationStart");
            args.Add("onstarttarget", showTipsObj);
            args.Add("onstartparams", "start");

            //args.Add("onupdate", "AnimationUpdate");
            //args.Add("onupdatetarget", showTipsObj);
            //args.Add("onupdateparams", true);

            args.Add("oncomplete", "AnimationEnd");
            args.Add("oncompleteparams", showTipsObj);
            args.Add("oncompletetarget", showTipsObj);

            args.Add("y", offset);

            iTween.MoveTo(showTipsObj, args);

            totalNum++;
        }
        catch (Exception ex)
        {
            Debug.Log("MsgTipsLogic " + ex.ToString());
        }

    }


}